import java.util.LinkedList;
import java.util.Scanner;
import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2025-07-20
 * Time: 13:31
 */
public class Test70 {

    public static boolean isValid(String s) {
        Stack<Character> st = new Stack<>();
        int n = s.length();
        char[] ch = s.toCharArray();
        for(int i = 0; i < n;i++) {
            if(ch[i] == '(' || ch[i] == '[' || ch[i] == '{') {
                st.push(ch[i]);
            }else {
                if(st.isEmpty()) {
                    return false;
                } else {
                    char x = st.peek();
                    if ((x == '(' && ch[i] == ')') || (x == '{' && ch[i] == '}') || (x == '[' && ch[i] == ']')){
                        st.pop();
                    } else {
                        return false;
                    }
                }
            }
        }
        return st.isEmpty();
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        boolean ret = isValid(s);
        System.out.println(ret);
    }

}
